package com.samphanie.auiu.route

import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.samphanie.auiu.R
import com.samphanie.auiu.common.ui.view.EmptyView
import com.samphanie.auiu.databinding.ActivityDegradeGlobalBinding
import com.samphanie.auiu.databinding.ActivityProfileDetailBinding

/**
 * 全局统一错误页
 */
@Route(path = "/degrade/global/activity")
class DegradeGlobalActivity : AppCompatActivity() {

    private lateinit var degradeGlobalBinding: ActivityDegradeGlobalBinding

    @JvmField
    @Autowired
    var degrade_title: String? = null
    @JvmField
    @Autowired
    var degrade_desc: String? = null
    @JvmField
    @Autowired
    var degrade_action: String? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ARouter.getInstance().inject(title)
        degradeGlobalBinding = ActivityDegradeGlobalBinding.inflate(layoutInflater)
        setContentView(degradeGlobalBinding.root)

        degradeGlobalBinding.emptyView.setIcon(R.string.if_unexpected1)
        if (degrade_title != null) {
            degradeGlobalBinding.emptyView.setTitle(degrade_title!!)
        }
        if (degrade_desc != null) {
            degradeGlobalBinding.emptyView.setDesc(degrade_desc!!)
        }
        if (degrade_action != null) {
            degradeGlobalBinding.emptyView.setHelpAction(listener = {
                val intent = Intent(Intent.ACTION_VIEW, Uri.parse(degrade_action))
                startActivity(intent)
            })
        }

        degradeGlobalBinding.actionBack.setOnClickListener {
            onBackPressed()
        }
    }
}